package com.example.tianhao.recycleviewtest_413th.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.tianhao.recycleviewtest_413th.R;
import com.example.tianhao.recycleviewtest_413th.bean.ArticleBean;
import com.example.tianhao.recycleviewtest_413th.adapter.MyAdapter;
import com.example.tianhao.recycleviewtest_413th.iface.ArticleListener;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;
    private List<ArticleBean> list=null;

    ArticleListener articleListener = new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> beanlist) {
            list=beanlist;
            myAdapter.setList(list);
            myAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this, "", Toast.LENGTH_SHORT).show();
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();

        //实例化ArticleModel，调用方法获取网络数据

    }

    private void initRecyclerView() {
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        //list=getData();
        myAdapter=new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);
    }

    /*private List<ArticleBean> getData()
    {//定义list 赋值   返回
        List<ArticleBean> list=new ArrayList<ArticleBean>();
        ArticleBean articleBean;

        articleBean=new ArticleBean();
        articleBean.setArticleId(1);
        articleBean.setTitle("标题1");
        articleBean.setDescription("描述1");
        articleBean.setImgid(R.drawable.f1);
        articleBean.setTime("2017-4-1");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(2);
        articleBean.setTitle("标题2");
        articleBean.setDescription("描述2");
        articleBean.setImgid(R.drawable.f2);
        articleBean.setTime("2017-4-2");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(3);
        articleBean.setTitle("标题3");
        articleBean.setDescription("描述3");
        articleBean.setImgid(R.drawable.f3);
        articleBean.setTime("2017-4-3");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(4);
        articleBean.setTitle("标题4");
        articleBean.setDescription("描述4");
        articleBean.setImgid(R.drawable.f4);
        articleBean.setTime("2017-4-4");
        list.add(articleBean);

        articleBean=new ArticleBean();
        articleBean.setArticleId(5);
        articleBean.setTitle("标题5");
        articleBean.setDescription("描述5");
        articleBean.setImgid(R.drawable.f5);
        articleBean.setTime("2017-4-5");
        list.add(articleBean);
        return list;
    }
*/


}
